package com.hzhc.controller.sysmanage;

import com.hzhc.annotation.SysTemLog;
import com.hzhc.common.BaseController;
import com.hzhc.entity.SysWxMenu;
import com.hzhc.enumBean.ResultUtilCodeEnum;
import com.hzhc.service.SysWxMenuService;
import com.hzhc.utils.ResultUtil;
import com.hzhc.vo.SysWxMenuVo;
import com.hzhc.vo.TreeVo;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 小程序菜单管理
 *
 * @author 功不唐捐
 * @since 2024-04-07
 */
@RestController
@RequestMapping("/sysWxMenu")
@RequiredArgsConstructor
public class SysWxMenuController extends BaseController {

    private final SysWxMenuService sysWxMenuService;

    /**
     * 菜单列表
     */
    @RequestMapping("/getMenuList")
    public ResultUtil<List<SysWxMenuVo>> getMenuList(@RequestBody SysWxMenuVo vo) {
        List<SysWxMenuVo> list = sysWxMenuService.getMenuList(vo);
        return ResultUtil.build(list, ResultUtilCodeEnum.SUCCESS);
    }

    /**
     * 菜单管理新增
     */
    @PostMapping("/saveMenu")
    @SysTemLog(operModul = "系统管理-微信菜单管理新增", operType = "新增", operDesc = "微信菜单管理新增功能", modular = "PC")
    public ResultUtil<T> saveMenu(@RequestBody SysWxMenu vo) {
        vo.setPid(vo.getPid() == null ? 0L : vo.getPid());
        return sysWxMenuService.saveMenu(vo);
    }

    /**
     * 菜单管理修改
     */
    @PostMapping("/updateMenu")
    @SysTemLog(operModul = "系统管理-微信菜单管理修改", operType = "修改", operDesc = "微信菜单管理修改功能", modular = "PC")
    public ResultUtil<T> updateMenu(@RequestBody SysWxMenu vo) {
        vo.setPid(vo.getPid() == null ? 0L : vo.getPid());
        return sysWxMenuService.updateMenu(vo);
    }

    /**
     * 微信菜单管理删除
     */
    @RequestMapping("/deleteMenu")
    @SysTemLog(operModul = "系统管理-微信菜单管理删除", operType = "删除", operDesc = "微信菜单管理删除功能", modular = "PC")
    public ResultUtil<T> deleteMenu(@RequestBody SysWxMenu menu) {
        return sysWxMenuService.deleteMenu(menu);
    }

    /**
     * 获取树形菜单
     */
    @RequestMapping("/getMenuTree")
    public ResultUtil<List<TreeVo>> getMenuTree(@RequestBody SysWxMenu menu) {
        menu.setPid(menu.getPid() == null ? 0L : menu.getPid());
        List<TreeVo> vos = sysWxMenuService.getMenuTree(menu.getPid());
        return ResultUtil.build(vos, ResultUtilCodeEnum.SUCCESS);
    }
}
